package com.dabay.web.util;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;


public class TimeUtil {

	public static String transTime(){
		long l = System.currentTimeMillis();
		//new日期对象
		Date date = new Date(l);
		//转换提日期输出格式
		SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		return dateFormat.format(date);
	}
	
	
	public int getYesterdayInt(){
		Calendar   cal   =   Calendar.getInstance();
	    cal.add(Calendar.DATE,-1);
		String yesterday = new SimpleDateFormat("yyyyMMdd").format(cal.getTime());
		return Integer.parseInt(yesterday);
	}
	public int getCurrentHHMMSS(){
		Calendar   cal   =   Calendar.getInstance();
		String timeStr = new SimpleDateFormat("HHmmss").format(cal.getTime());
		return Integer.parseInt(timeStr);
	}
	public int getLastMonthInt(){
		Calendar   cal   =   Calendar.getInstance();
	    cal.add(Calendar.DATE,-30);
		String yesterday = new SimpleDateFormat("yyyyMMdd").format(cal.getTime());
		return Integer.parseInt(yesterday);
	}
	public String getDeleteMonthInt(){
		Calendar   cal   =   Calendar.getInstance();
	    cal.add(Calendar.DATE,-28);
		String yesterday = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(cal.getTime());
		return yesterday;
	}
	public int getIntByDateStr(String dateStr){
		if(dateStr==null || dateStr=="" || dateStr.length()<10 ){
			return 0;
		}
		dateStr = dateStr.substring(0, 10).replaceAll("-", "");
		return Integer.parseInt(dateStr);
	}

	public static int getLastTwoMonth(){
		Calendar   cal   =   Calendar.getInstance();
	    cal.add(Calendar.MONTH,-2);
		String yesterday = new SimpleDateFormat("yyyyMM").format(cal.getTime());
		return Integer.parseInt(yesterday);
	}
	
}
